package com.example.demo.core.repository;

import com.example.demo.core.entity.RolePermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface RolePermissionRepository extends JpaRepository<RolePermission, Integer> {

    /**
    * @Description: 获取某个角色的所有权限
    * @Param:  roleId: 角色ID
    * @return:  角色权限对应列表
    * @Author: wangze
    */
    List<RolePermission> findAllByRoleId(Integer roleId);

    /**
    * @Description: 根据角色ID删除对应权限
    * @param roleId 角色ID
    * @return: 无
    * @Author: wangze
    */
    @Transactional
    @Modifying
    void deleteAllByRoleId(Integer roleId);

    /**
    * @Description: 根据角色ID和权限ID删除角色权限表中的项
    * @param roleId 角色ID
     * @param permissionId 权限ID
    * @return:  无
    * @Author: wangze
    */
    @Transactional
    @Modifying
    void deleteAllByRoleIdAndPermissionId(Integer roleId, Integer permissionId);
}
